
//
//  CommentTableViewCell.m
//  Project_B
//
//  Created by 张闯的mac pro on 15/11/25.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "CommentTableViewCell.h"
#import "FirstModel.h"
#import "CalculateHeight.h"
#import "UIImageView+WebCache.h"

@interface CommentTableViewCell ()

@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *timeLabel;
@property (nonatomic, retain) UILabel *floorLabel;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *contentLabel;
@property (nonatomic, retain) UIImageView *titleImg;
@property (nonatomic, retain) UIImageView *contentImg;

@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;

@end

@implementation CommentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        
        self.nameLabel = [[UILabel alloc] init];
        self.nameLabel.textColor = [UIColor grayColor];
        [self.nameLabel setFont:[UIFont systemFontOfSize:13]];
        [self.contentView addSubview:self.nameLabel];
        
        self.timeLabel = [[UILabel alloc] init];
        self.timeLabel.textColor = [UIColor grayColor];
        [self.timeLabel setFont:[UIFont systemFontOfSize:13]];
        [self.contentView addSubview:self.timeLabel];
        
        self.floorLabel = [[UILabel alloc] init];
        self.floorLabel.textColor = [UIColor grayColor];
        [self.floorLabel setFont:[UIFont systemFontOfSize:13]];
        [self.contentView addSubview:self.floorLabel];
        
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.textColor = [UIColor grayColor];
        [self.contentLabel setFont:[UIFont systemFontOfSize:13]];
        self.contentLabel.numberOfLines = 0;
        [self.contentView addSubview:self.contentLabel];
        
        self.titleImg = [[UIImageView alloc] init];
        [self.contentView addSubview:self.titleImg];
        
        self.contentImg = [[UIImageView alloc] init];
        [self.contentView addSubview:self.contentImg];
        
    }
    return self;
}


- (void)setModel:(FirstModel *)model
{
    if (_model != model) {
        _model = model;
    }
    
    [self.titleImg sd_setImageWithURL:[NSURL URLWithString:model.headicon] placeholderImage:[UIImage imageNamed:@""]];
    self.nameLabel.text = model.nickname;
    self.timeLabel.text = model.createdate;
    self.floorLabel.text = [NSString stringWithFormat:@"%@楼", model.floor];
    self.titleLabel.text = model.title;
    self.contentLabel.text = model.content;
    [self.contentImg sd_setImageWithURL:[NSURL URLWithString:((NSArray *)model.topic_image).firstObject[@"image"]] placeholderImage:[UIImage imageNamed:@""]];
    
    self.width = [((NSArray *)model.topic_image).firstObject[@"width"] floatValue];
    self.height = [((NSArray *)model.topic_image).firstObject[@"height"] floatValue];

}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.titleImg.frame = CGRectMake(15, 10, 40, 40);
    self.nameLabel.frame = CGRectMake(60, 13, 150, 15);
    self.timeLabel.frame = CGRectMake(60, 30, 150, 15);
    self.floorLabel.frame = CGRectMake(345, 25, 30, 15);
   // self.titleLabel.frame = CGRectMake(18, self.titleImg.frame.origin.y + self.titleImg.frame.size.height + 10, 200, 20);
    
    CGFloat h = [CalculateHeight heightWithText:self.contentLabel.text fontSize:13];
    
    self.contentLabel.frame = CGRectMake(15, self.timeLabel.frame.origin.y + self.timeLabel.frame.size.height + 20, 375 - 30, h);
    
    self.contentImg.frame = CGRectMake(15, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 5, 375 - 30, 300);
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
